$("#firestart").on('click', fireStart);
function fireStart(){
    //交互提醒
    common.showMsg('选择发生火情处',2);

    //界面更新

        //主视图更新

            //前步骤元素清理
        clearInterval(pointTimeId);
        viewer.entities.removeAll();
        if(viewer.scene.primitives._primitives[1]){
            viewer.scene.primitives.remove(viewer.scene.primitives._primitives[1])
        };
        viewer.scene.scanEffect.show = false;
            //隐藏吊顶
        let layer_upper = viewer.scene.layers.find("F1@听海大道地下空间20201016");
        layer_upper.visible = false;
            //切换至俯视视角
        viewer.scene.camera.setView({
            destination:{ x: -2386275.095372156, y: 5386727.290105708, z: 2445134.9587714258 },
            orientation:{heading:1.5549424995174963, pitch:-1.5350281966828634, roll:0}
        })

        //交互界面更新
        $('#floorclose').addClass('hide');
        $('#stopfly').addClass('hide');

        $('#escape').addClass('hide');
        $('#startfly').addClass('hide');
        $('#firestart').addClass('hide');
        $('#stopfly').addClass('hide');
        $('#floorclose').addClass('hide');

    //变量初始化
    barrierArea = [];
    let handlerPoint = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)

    //功能主程序
    handlerPoint.setInputAction(function(e){
        let pos = viewer.scene.pickPosition(e.position);
        let cartographic = Cesium.Cartographic.fromCartesian(pos);
        let lon = Cesium.Math.toDegrees(cartographic.longitude);
        let lat = Cesium.Math.toDegrees(cartographic.latitude);
        //查询障碍点ID
        let leftBottom = {"x":lon - 0.00008,"y":lat - 0.00008};
        let rightTop = {"x":lon + 0.00008 ,"y":lat + 0.00008};
        let queryObj = {
            getFeatureMode: "BOUNDS",
            datasetNames: ["underground_tinghai:underground_Network_Node"],
            bounds: '{"leftBottom":{"x":' + leftBottom.x + ',"y":' + leftBottom.y +'},"rightTop":{"x":' + rightTop.x +',"y":' +rightTop.y + '}}',
          };

        let queryObjJSON = JSON.stringify(queryObj); // 转化为JSON字符串作为查询参数
        let given_str = "/featureResults.json?returnContent=true";
        $.ajax({
            type: "post",
            url: SYS.dataUrl + given_str,
            data: queryObjJSON,
            success: function (result) {
              console.log(result);
              var j = 0;
              for(result.features[j];j<result.featureCount; j++){
                  barrierArea.push(result.features[j].ID)
              }
              
            },
            error: function (msg) {
              console.log(msg);
            },
        });

        //设置放火效果
            //设置参数
        let viewModel = {
            emissionRate: 200.0,
            gravity: 0.0,
            minimumParticleLife: 1.5,
            maximumParticleLife: 1.8,
            minimumSpeed: 7.0,
            maximumSpeed: 9.0,
            startScale: 3.0,
            endScale: 1.5,
            particleSize: 2,
        };

        let entity = viewer.entities.add({
            position: pos
        })

            //entity操作
            // .computeModelMatrix()  ?
        function computeModelMatrix(entity,time){
            return entity.computeModelMatrix(time, new Cesium.Matrix4());
        }

            //粒子系统位置初始化
        var emitterModelMatrix = new Cesium.Matrix4();
        var translation = new Cesium.Cartesian3();
        var rotation = new Cesium.Quaternion();
        var hpr = new Cesium.HeadingPitchRoll();
        var trs = new Cesium.TranslationRotationScale();

            //改变粒子系统位置
        function computeEmitterModelMatrix() {
            hpr = Cesium.HeadingPitchRoll.fromDegrees(0.0, 0.0, 0.0, hpr);
            trs.translation = Cesium.Cartesian3.fromElements(0, 0, 0, translation);
            trs.rotation = Cesium.Quaternion.fromHeadingPitchRoll(hpr, rotation);
            return Cesium.Matrix4.fromTranslationRotationScale(trs, emitterModelMatrix);
        }

            //将粒子系统加入场景
        var particleSystem = viewer.scene.primitives.add(new Cesium.ParticleSystem({
            image: '../images/fire4.png',
            startColor: new Cesium.Color(1, 1, 1, 1),
            endColor: new Cesium.Color(0.1, 0, 0, 0),
            startScale: viewModel.startScale,
            endScale: viewModel.endScale,
            minimumParticleLife: viewModel.minimumParticleLife,
            maximumParticleLife: viewModel.maximumParticleLife,
            minimumSpeed: viewModel.minimumSpeed,
            maximumSpeed: viewModel.maximumSpeed,
            imageSize: new Cesium.Cartesian2(viewModel.particleSize, viewModel.particleSize),
            emissionRate: viewModel.emissionRate,
            lifetime: 6.0,
            loop: true,
            emitter: new Cesium.ConeEmitter(Cesium.Math.toRadians(45.0)),
            sizeInMeters: true,
        }))

            //**关键属性：使scene颜色不受粒子系统影响
        viewer.scene.logarithmicDepthBuffer = false;

            //ModelMatrix 处理
                //preUpdate  ?
        viewer.scene.preUpdate.addEventListener(function (scene, time){
            particleSystem.modelMatrix = computeModelMatrix(entity, time);
            particleSystem.emitterModelMatrix = computeEmitterModelMatrix();
        })
        //销毁鼠标事件触发
        handlerPoint = handlerPoint && handlerPoint.destroy();  

    //进入下道程序
        selectPoints();
},Cesium.ScreenSpaceEventType.LEFT_CLICK)
}